# Contributor: rubicon <rubicon@mailo.com>
# Maintainer: Celeste <cielesti@protonmail.com>
maintainer="Celeste <cielesti@protonmail.com>"
pkgname=ocaml-tcpip
_pkgname=tcpip
pkgver=7.1.2
pkgrel=3
pkgdesc="OCaml TCP/IP networking stack, used in MirageOS"
url="https://github.com/mirage/mirage-tcpip"
arch="all !riscv64 !loongarch64" # ocaml
license="ISC"
# ocaml-bisect_ppx only needed for dev
depends_dev="
	$pkgname=$pkgver-r$pkgrel
	ocaml-arp-dev
	ocaml-bisect_ppx-dev
	ocaml-cstruct-dev
	ocaml-duration-dev
	ocaml-ethernet-dev
	ocaml-fmt-dev
	ocaml-ipaddr-dev
	ocaml-logs-dev
	ocaml-lru-dev
	ocaml-lwt-dev
	ocaml-lwt-dllist-dev
	ocaml-metrics-dev
	ocaml-mirage-clock-dev
	ocaml-mirage-flow-dev
	ocaml-mirage-net-dev
	ocaml-mirage-profile-dev
	ocaml-mirage-random-dev
	ocaml-mirage-time-dev
	ocaml-randomconv-dev
	"
makedepends="$depends_dev dune ocaml"
checkdepends="ocaml-alcotest-dev ocaml-ipaddr-cstruct-dev ocaml-mirage-clock-unix-dev ocaml-mirage-random-test-dev ocaml-mirage-vnetif-dev ocaml-pcap-format-dev"
options="!check"
subpackages="$pkgname-dev"
source="$pkgname-$pkgver.tar.bz2::https://github.com/mirage/mirage-tcpip/releases/download/v$pkgver/tcpip-$pkgver.tbz"
builddir="$srcdir/$_pkgname-$pkgver"
_ocamldir=usr/lib/ocaml

# 32-bit archs
case "$CARCH" in
	arm*|x86) options="$options textrels" ;;
esac

build() {
	dune build --release --verbose
}

check() {
	dune runtest --verbose
}

package() {
	dune install \
		--destdir="$pkgdir" \
		--docdir=/.omit
	rm -Rf "$pkgdir"/.omit
}

dev() {
	default_dev

	cd "$pkgdir"

	local path; find $_ocamldir \( \
			-name '*.cmt' -o \
			-name '*.cmti' -o \
			-name '*.ml' -o \
			-name '*.mli' \
		\) | while read -r path
	do
		amove "$path"
	done
}

prepare_py_provides() {
	local datadir="${subpkgdir:-$pkgdir}"
	local pkgbasedir=${pkgbasedir:-"$startdir/pkg"}
	local controldir="$pkgbasedir"/.control.${subpkgname:-$pkgname}

	options_has "!tracedeps" && return 0

	ocaml4-abuild-find provides \
		"$datadir"/usr/lib/ocaml \
		"$controldir" \
		"$pkgver-r$pkgrel"
}

scan_python3_dependency() {
	local controldir="$2" datadir="$3"

	ocaml4-abuild-find requires \
		"$datadir"/usr/lib/ocaml \
		"$controldir"
}

sha512sums="
3f873c986de5c58df72db2953c6b2a6319963dbbbd0781b55c2878fd1eaa081ebb7cecbee595db7cb3680a6f438904f98cb69ca17e70c7a6d2d1f61277e929bd  ocaml-tcpip-7.1.2.tar.bz2
"
